package sg.edu.nus.iss.billing.model.bill;

import java.text.DecimalFormat;

import sg.edu.nus.iss.billing.model.BaseModel;
import sg.edu.nus.iss.billing.model.transaction.PaymentTransaction;

/**
 * @author ZiFeng, YinNi, Thurien
 */
public class BillReport extends BaseModel {

	private static final long serialVersionUID = 1L;
	private double previousBalance = 0;
	private double payments = 0;
	private double currentCharges = 0;
	
	@SuppressWarnings("unused")
	private double digitalSubscriptionCharges = 0;
	@SuppressWarnings("unused")
	private double digitalUsageCharges = 0;
	@SuppressWarnings("unused")
	private double mobileSubscriptionCharges = 0;
	@SuppressWarnings("unused")
	private double mobileUsageCharges = 0;
	@SuppressWarnings("unused")
	private double totalDigitalSubscriptionCharges = 0;
	@SuppressWarnings("unused")
	private double totalDigitalUsageCharges = 0;
	@SuppressWarnings("unused")
	private double totalDigitalCharges = 0;
	@SuppressWarnings("unused")
	private double totalMobileSubscriptionCharges = 0;
	@SuppressWarnings("unused")
	private double totalMobilelUsageCharges = 0;
	@SuppressWarnings("unused")
	private double totalMobileCharges = 0;
	@SuppressWarnings("unused")
	private double totalCableCharges = 0;
	@SuppressWarnings("unused")
	private double totalChargesWithoutGST = 0;
	@SuppressWarnings("unused")
	private double totalGST = 0;
	@SuppressWarnings("unused")
	private double totalCurrentCharges = 0;

	private double cableTVSubscriptionCharges = 0;
	private double cableTVUsageCharges = 0;

	private double digitalLine = 0;
	private double digitalCallTranster = 0;
	private double digitalLocalCalls = 0;
	private double digitalIDDCalls = 0;

	private double mobileLine = 0;
	private double mobileRoaming = 0;
	private double mobileDataServices = 0;
	private double mobileLocalCalls = 0;
	private double mobileIDDCalls = 0;
	private double mobileRoamingCalls = 0;
	private int additionalCableCount = 0;
	
	private String dueDate;
	private String billDate;
	private PaymentTransaction payment;
	private String mobileNum;
	private String digitalNum;
	private String cableNum;
	private double currentBalance;

	private String digitalLineDays;
	private String digitalCallTransterDays;
	private String mobileDataServiceDays;
	private String mobileRoamingDays;
	private String mobileLineDays;
	
	private String additionalCableCountLable;

	public String getAdditionalCableCountLable() {
		if(additionalCableCountLable == null)
			additionalCableCountLable="";
		return additionalCableCountLable;
	}

	public void setAdditionalCableCountLable(String additionalCableCountLable) {
		this.additionalCableCountLable = additionalCableCountLable;
	}

	public double getPreviousBalance() {
		return roundTwoDecimals(previousBalance);
	}

	public void setPreviousBalance(double previousBalance) {
		this.previousBalance = previousBalance;
	}

	public double getPayments() {
		return roundTwoDecimals(payments);
	}

	public void setPayments(double payments) {
		this.payments = payments;
	}

	public double getCurrentCharges() {
		return roundTwoDecimals(currentCharges);
	}

	public void setCurrentCharges(double currentCharges) {
		this.currentCharges = currentCharges;
	}

	public double getDigitalSubscriptionCharges() {
		return roundTwoDecimals(digitalLine + digitalCallTranster);
	}

	public double getDigitalUsageCharges() {
		return roundTwoDecimals(digitalLocalCalls + digitalIDDCalls);
	}

	public double getMobileSubscriptionCharges() {
		return roundTwoDecimals(mobileLine + mobileRoaming + mobileDataServices);
	}

	public double getMobileUsageCharges() {
		return roundTwoDecimals(mobileLocalCalls + mobileIDDCalls + mobileRoamingCalls);
	}

	public double getCableTVSubscriptionCharges() {
		return roundTwoDecimals(cableTVSubscriptionCharges);
	}

	public void setCableTVSubscriptionCharges(double cableTVSubscriptionCharges) {
		this.cableTVSubscriptionCharges += cableTVSubscriptionCharges;
	}

	public double getCableTVUsageCharges() {
		return roundTwoDecimals(cableTVUsageCharges);
	}

	public void setCableTVUsageCharges(double cableTVUsageCharges) {
		this.cableTVUsageCharges += cableTVUsageCharges;
	}

	public void setAdditionalCableCount(int count) {
		this.additionalCableCount = count;
	}

	public int getAdditionalCableCount(int count) {
		return this.additionalCableCount;
	}

	public double getDigitalLine() {
		return roundTwoDecimals(digitalLine);
	}

	public void setDigitalLine(double digitalLine) {
		this.digitalLine += digitalLine;
	}

	public double getDigitalLocalCalls() {
		return roundTwoDecimals(digitalLocalCalls);
	}

	public void setDigitalLocalCalls(double digitalLocalCalls) {
		this.digitalLocalCalls = digitalLocalCalls;
	}

	public double getDigitalIDDCalls() {
		return roundTwoDecimals(digitalIDDCalls);
	}

	public void setDigitalIDDCalls(double digitalIDDCalls) {
		this.digitalIDDCalls = digitalIDDCalls;
	}

	public double getMobileLine() {
		return roundTwoDecimals(mobileLine);
	}

	public void setMobileLine(double mobileLine) {
		this.mobileLine += mobileLine;
	}

	public double getMobileRoaming() {
		return roundTwoDecimals(mobileRoaming);
	}

	public void setMobileRoaming(double mobileRoaming) {
		this.mobileRoaming += mobileRoaming;
	}

	public double getMobileDataServices() {
		return roundTwoDecimals(mobileDataServices);
	}

	public void setMobileDataServices(double mobileDataServices) {
		this.mobileDataServices += mobileDataServices;
	}

	public double getMobileLocalCalls() {
		return roundTwoDecimals(mobileLocalCalls);
	}

	public void setMobileLocalCalls(double mobileLoacalCalls) {
		this.mobileLocalCalls = mobileLoacalCalls;
	}

	public double getMobileIDDCalls() {
		return roundTwoDecimals(mobileIDDCalls);
	}

	public void setMobileIDDCalls(double mobileIDDCalls) {
		this.mobileIDDCalls = mobileIDDCalls;
	}

	public double getMobileRoamingCalls() {
		return roundTwoDecimals(mobileRoamingCalls);
	}

	public void setMobileRoamingCalls(double mobileRoamingCalls) {
		this.mobileRoamingCalls = mobileRoamingCalls;
	}

	public double getDigitalCallTranster() {
		return roundTwoDecimals(digitalCallTranster);
	}

	public void setDigitalCallTranster(double digitalCallTranster) {
		this.digitalCallTranster += digitalCallTranster;
	}

	public double getTotalDigitalCharges() {
		return roundTwoDecimals(getTotalDigitalSubscriptionCharges() + getTotalDigitalUsageCharges());
	}

	public double getTotalMobileCharges() {
		return roundTwoDecimals(getTotalMobilelUsageCharges() + getTotalMobileSubscriptionCharges());
	}

	public double getTotalCableCharges() {
		return roundTwoDecimals(getCableTVSubscriptionCharges() + getCableTVUsageCharges());
	}

	public double getTotalChargesWithoutGST() {
		return roundTwoDecimals(getTotalDigitalCharges() + getTotalMobileCharges() + getTotalCableCharges());
	}

	public double getTotalGST() {
		return roundTwoDecimals(getTotalChargesWithoutGST() * 0.07);
	}

	public double getTotalCurrentCharges() {
		return roundTwoDecimals(getTotalChargesWithoutGST() + getTotalGST());
	}

	public double getTotalDigitalSubscriptionCharges() {
		return roundTwoDecimals(digitalLine + digitalCallTranster);
	}

	public double getTotalDigitalUsageCharges() {
		return roundTwoDecimals(digitalLocalCalls + digitalIDDCalls);
	}

	public double getTotalMobileSubscriptionCharges() {
		return roundTwoDecimals(mobileLine + mobileRoaming + mobileDataServices);
	}

	public double getTotalMobilelUsageCharges() {
		return roundTwoDecimals(mobileLocalCalls + mobileIDDCalls + mobileRoamingCalls);
	}

	public PaymentTransaction getPayment() {
		return payment;
	}

	public void setPayment(PaymentTransaction payment) {
		this.payment = payment;
	}

	private double roundTwoDecimals(double d) {
		DecimalFormat twoDForm = new DecimalFormat("#.##");
		return Double.valueOf(twoDForm.format(d));
	}

	public String getDueDate() {
		return dueDate;
	}

	public void setDueDate(String dueDate) {
		this.dueDate = dueDate;
	}

	public String getBillDate() {
		return billDate;
	}

	public void setBillDate(String billDate) {
		this.billDate = billDate;
	}

	public String getMobileNum() {
		return mobileNum;
	}

	public void setMobileNum(String mobileNum) {
		this.mobileNum = mobileNum;
	}

	public String getDigitalNum() {
		return digitalNum;
	}

	public void setDigitalNum(String digitalNum) {
		this.digitalNum = digitalNum;
	}

	public String getCableNum() {
		return cableNum;
	}

	public void setCableNum(String cableNum) {
		this.cableNum = cableNum;
	}

	public double getCurrentBalance() {
		double balance = roundTwoDecimals(currentBalance);
		return balance < 0? 0.00: balance;
	}

	public void setCurrentBalance(double currentBalance) {
		this.currentBalance = currentBalance;
	}

	public void setDigitalLineDays(String digitalLineDays) {
		try {
			if(this.digitalLineDays != null) {
				int existingLineDays = Integer.parseInt(this.digitalLineDays);
				int newLineDays = Integer.parseInt(digitalLineDays);
				
				this.digitalLineDays = (existingLineDays + newLineDays) + "";
			}
			else {
				this.digitalLineDays = digitalLineDays;
			}
		}
		catch(NumberFormatException ex) {
			ex.printStackTrace();
		}
	}

	public void setDigitalCallTransterDays(String digitalCallTransterDays) {
		try {
			if(this.digitalCallTransterDays != null) {
				int existingLineDays = Integer.parseInt(this.digitalCallTransterDays);
				int newLineDays = Integer.parseInt(digitalCallTransterDays);
				
				this.digitalCallTransterDays = (existingLineDays + newLineDays) + "";
			}
			else {
				this.digitalCallTransterDays = digitalCallTransterDays;
			}
		}
		catch(NumberFormatException ex) {
			ex.printStackTrace();
		}
	}

	public void setMobileDataServiceDays(String mobileDataServiceDays) {
		try {
			if(this.mobileDataServiceDays != null) {
				int existingLineDays = Integer.parseInt(this.mobileDataServiceDays);
				int newLineDays = Integer.parseInt(mobileDataServiceDays);
				
				this.mobileDataServiceDays = (existingLineDays + newLineDays) + "";
			}
			else {
				this.mobileDataServiceDays = mobileDataServiceDays;
			}
		}
		catch(NumberFormatException ex) {
			ex.printStackTrace();
		}
	}

	public void setMobileRoamingDays(String mobileRoamingDays) {
		try {
			if(this.mobileRoamingDays != null) {
				int existingLineDays = Integer.parseInt(this.mobileRoamingDays);
				int newLineDays = Integer.parseInt(mobileRoamingDays);
				
				this.mobileRoamingDays = (existingLineDays + newLineDays) + "";
			}
			else {
				this.mobileRoamingDays = mobileRoamingDays;
			}
		}
		catch(NumberFormatException ex) {
			ex.printStackTrace();
		}
	}

	public void setMobileLineDays(String mobileLineDays) {
		try {
			if(this.mobileLineDays != null) {
				int existingLineDays = Integer.parseInt(this.mobileLineDays);
				int newLineDays = Integer.parseInt(mobileLineDays);
				
				this.mobileLineDays = (existingLineDays + newLineDays) + "";
			}
			else {
				this.mobileLineDays = mobileLineDays;
			}
		}
		catch(NumberFormatException ex) {
			ex.printStackTrace();
		}
	}

	public String getDigitalLineDays() {
		return "Number of Days:" + digitalLineDays;
	}

	public String getDigitalCallTransterDays() {
		return "Number of Days:" + digitalCallTransterDays;
	}

	public String getMobileDataServiceDays() {
		return "Number of Days:" + mobileDataServiceDays;
	}

	public String getMobileRoamingDays() {
		return "Number of Days:" + mobileRoamingDays;
	}

	public String getMobileLineDays() {
		return "Number of Days:" + mobileLineDays;
	}
}
